// pages/publicOrderView/publicOrderView.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    chooseTypeArray: [
      { typeName: "driver", typeSel: false, typeTitle: "我是司机", iconName: "/images/publicView/driverIcon" },
      { typeName: "passenger", typeSel: false, typeTitle: "我是乘客", iconName: "/images/publicView/passengerIcon" },
      { typeName: "once", typeSel: false, typeText: "1", typeTitle: "单次拼车", typeTip: "到期自动删除", iconName: "/images/publicView/cycIcon" },
      { typeName: "cyc", typeSel: false, typeText: "N", typeTitle: "循环拼车", typeTip: "循环展示一周", iconName: "/images/publicView/cycIcon" },
    ],

    isReadyGo:false,
    isVerifled:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    let self = this
    let app = getApp()
    let logged = app.globalData.logged
    let userInfo = null

    if (logged = true) {
      userInfo = app.globalData.userInfo
      self.setData({ logged: logged, userInfo: userInfo, isVerifled:true })
    }
    console.log("logged", logged, userInfo)


  },
  navToContactInfo: function (res) {
    console.log("fixss")
    wx.navigateTo({
      url: '/pages/mineInfoView/mineInfoView',
    })
  },

  chooseTypeTapped: function (res) {
    let self = this
    let chooseTypeArray = self.data.chooseTypeArray
    let btnName = res.currentTarget.dataset.choosetype
    var isReadyGo = self.data.isReadyGo

    var upBool = false
    var bottomBool = false

    for (var index in chooseTypeArray) {
      let model = chooseTypeArray[index]
      if (model.typeName == btnName) {
        model.typeSel = !model.typeSel
        if ((index == 0 || index == 1) && (chooseTypeArray[0].typeSel == true || chooseTypeArray[1].typeSel == true)) {
          if (index == 1) {
            chooseTypeArray[0].typeSel = !chooseTypeArray[1].typeSel
          } else {
            chooseTypeArray[1].typeSel = !chooseTypeArray[0].typeSel
          }
        }
        if ((index == 2 || index == 3) && (chooseTypeArray[2].typeSel == true || chooseTypeArray[3].typeSel == true)) {
          if (index == 3) {
            chooseTypeArray[2].typeSel = !chooseTypeArray[3].typeSel
          } else {
            chooseTypeArray[3].typeSel = !chooseTypeArray[2].typeSel
          }
        }
      }
    }

    for (var index in chooseTypeArray) {
      if ((index == 0 || index == 1) && (chooseTypeArray[0].typeSel == true || chooseTypeArray[1].typeSel == true)) {
        upBool = true
      }
      if ((index == 2 || index == 3) && (chooseTypeArray[2].typeSel == true || chooseTypeArray[3].typeSel == true)) {
        var bottomBool = true
      }
    }


    var scaleRotate = 1
    if (bottomBool && upBool){
      isReadyGo  = true
      scaleRotate = 1.2
    }else{
      isReadyGo = false
      scaleRotate = 1
    }

    var animation = wx.createAnimation({
      duration: 500,
      timingFunction: "ease",
    })

    console.log("isReadyGo", upBool, bottomBool, isReadyGo)
    animation.scale(scaleRotate, scaleRotate).step()

    self.setData({ chooseTypeArray: chooseTypeArray, isReadyGo: isReadyGo, bottomBool: bottomBool, upBool: upBool, animation: animation.export()})
  },
  

  addOtherInfo: function () {
    let isReadyGo = this.data.isReadyGo
    let isVerifled = this.data.isVerifled
    if (isVerifled == false){
      wx.showToast({
        image: '/images/noWayWhite.png',
        title: '请点击修改',
      })
      return
    }else if (isReadyGo == false){
      wx.showToast({
        image:'/images/noWayWhite.png',
        title: '请选择相应类型',
      })
    }else{
      let self = this
      let chooseTypeArray = self.data.chooseTypeArray
      let driverType = ''
      let driverFun = ''
      for (var index in chooseTypeArray){
        let model = chooseTypeArray[index]
        if (model.typeSel == true &&(index < 2)){
          driverType = model.typeName
        } else if (model.typeSel == true && (index > 1)){
          driverFun = model.typeName
        }
      }
      console.log('tiao', driverType, driverFun)

      wx.navigateTo({
        url: '/pages/driverView/driverView?driverType=' + driverType + '&driverFun=' + driverFun,
      })
    }
    

  },





  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})